
#include "fifo.h"
#include "my_macros.h"
#include "Debug.h"


#define   EVENT_FIFO_BUFFER_SIZE		12

enum
{
	EVENT__LABEL_START = 1,		  /* must be first in the list of events */
	EVENT__POWER_UP,
	EVENT__NETWORK_REGISTRATION,
	
	EVENT__INPUTS,
	EVENT__INPUT_1_UP,
	EVENT__INPUT_1_DOWN,
	EVENT__INPUT_2_UP,
	EVENT__INPUT_2_DOWN,
	EVENT__INPUT_3_UP,
	EVENT__INPUT_3_DOWN,
	EVENT__INPUT_4_UP,
	EVENT__INPUT_4_DOWN,
	
	EVENT__INCOMING_CALL,		  /* any call */
	EVENT__INCOMING_CALL_OF_DEFAULT_USER,

	EVENT__INCOMING_SMS,			  /* any SMS */
	EVENT__INCOMING_SMS_COMMAND,
	
	EVENT__NONE						  /* must be last in the list of events */
};

typedef struct
{
		unsigned char DeviceName;
		unsigned char Event;
}EVENT;


unsigned char Events_Queue_Buffer[EVENT_FIFO_BUFFER_SIZE];

FIFO_INF Events_Queue;

void Event_Init ( void )
{
	Fifo_Init( &Events_Queue, Events_Queue_Buffer, EVENT_FIFO_BUFFER_SIZE);
}

/* if return (-1) - error; */
int Event_Add ( unsigned char Event )
{
	if ( Event <= EVENT__LABEL_START || Event > EVENT__NONE )
	{
		return -1;
	}
  	
	return Fifo_Write(&Events_Queue, (unsigned char*)&Event, 1);	
}

/* read ONE event (one byte) from the queue; return 0 - none events */
unsigned char Event_Read ( unsigned char *Event )
{
	return Fifo_nRead(&Events_Queue, Event, 1); 
}

